﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using InfoKiosk;

namespace InfoPage
{
    public partial class InfoPageControl : UserControl, IInfoPage
    {
        public InfoPageControl()
        {
            InitializeComponent();
        }

        #region Required IInfoPage Implementation
        // this public property is populated by the Kiosk Page.xaml if
        // any Parameter elements are specified for the page
        public List<IComponentParameter> ComponentParameters { get; set; }
 
        /// <summary>
        /// This is a required method, void return type and no parameters.
        /// The content of the method is completely up to the coder or 
        /// designer if you wish...
        /// </summary>
        public void Start()
        {
            VideoTimeline.Completed += new EventHandler(storyboard_completed);

            // Get the message from the ComponentParameter collection as
            // specified in the PageControl.XML which is located in the
            // ClientBin folder on the hosting web site
            String message = ComponentParameters.Where(
                param => param.Key == "MessageToShow").First().Value;

            messages = message.Split(';');
        }

        #endregion
 
        private String[] messages = null;
        private Int32 count = 0;

        private void Page_Loaded(object sender, EventArgs e)
        {
            VideoTimeline.Begin();
        }

        void storyboard_completed(object sender, EventArgs e)
        {
            if (count == messages.Length)
            {
                count = 0;
            }

            message.Text = messages[count];
            count++;
            VideoTimeline.Begin();
        }
    }
}
